package com.tecnalia.authz.pep;

import com.tecnalia.authz.common.XACMLConstants;

public class Test {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String subject = "user3";
		int queryMode = XACMLConstants.XACML_QUERY_Strict;
		String action = "read";
		String service = "recurso3";
		
		PEPData pep = new PEPData();
		
		//Se fija el modo en el que vamos a consultar
		pep.setQueryMode(queryMode);

		//Se fija el usuario 
		pep.setSubject(subject);
		//Se fija la accion
		pep.setAction(action);
		//Se fija el servicio
		pep.addService(service);
		
		//Se lanza la Query
		int res = (Integer) pep.fireQuery();
		
		System.out.print("XACML Query Response is " + DecisionToString(res));
	}

	private static String DecisionToString(int res){
		if(res == org.jboss.security.xacml.interfaces.XACMLConstants.DECISION_PERMIT){
			return "DECISION_PERMIT";
		}
		if(res == org.jboss.security.xacml.interfaces.XACMLConstants.DECISION_DENY){
			return "DECISION_DENY";
		}
		if(res == org.jboss.security.xacml.interfaces.XACMLConstants.DECISION_INDETERMINATE){
			return "DECISION_INDETERMINTE";
		}
		if(res == org.jboss.security.xacml.interfaces.XACMLConstants.DECISION_NOT_APPLICABLE){
			return "DECISION_NOT_APPLICABLE";
		}
		return null;
	}
}
